﻿using ctolua.Models.Class;
using ctolua.Models.Enum;

namespace ctolua.Models.UI.control
{
    public class MCRichText : Mui
    {
        public override EUi type { get => EUi.富文本; set => base.type = EUi.富文本; }
        public MCRichText()
        {
        }

        public MCRichText(string id) : base(id)
        {
        }

        public MCRichText(MCRichText u) : base(u)
        {
            this.text = u.text;
            this.size = u.size;
            this.min_size = u.min_size;
            this.is_open = u.is_open;
            this.align_type = u.align_type;
            this.color = u.color;
            this.bind_attr = u.bind_attr;
            this.bind_attr_unit = u.bind_attr_unit;
        }
        private string _text;
        /// <summary>
        /// 文本
        /// </summary>
        public string text
        {
            get => _text;
            set
            {
                if (value != null)
                {
                    game_api.set_ui_comp_text(this.role, this.id, value);
                }

                _text = value;
            }
        }

        private int? _size;
        /// <summary>
        /// 字体大小
        /// </summary>
        public int? size
        {
            get => _size;
            set
            {
                if (value != null)
                {
                    game_api.set_ui_comp_font_size(this.role, this.id, value);
                }

                _size = value;
            }
        }

        private int? _min_size;
        /// <summary>
        /// 字体大小跟随内容
        /// </summary>
        public int? min_size
        {
            get => _min_size;
            set
            {
                if (value != null)
                {
                    game_api.set_ui_comp_text_adaptive_min_size(this.role, value);
                }

                _min_size = value;
            }
        }

        private bool? _is_open;
        /// <summary>
        /// 开启字体大小跟随内容自适应
        /// </summary>
        public bool? is_open
        {
            get => _is_open;
            set
            {
                if (value != null)
                {
                    game_api.set_ui_comp_text_adaptive(this.role, this.id, value);
                }

                _is_open = value;
            }
        }

        private int? _align_type;
        /// <summary>
        /// 设置控件文本对齐方式
        /// </summary>
        public int? align_type
        {
            get => _align_type;
            set
            {
                if (value != null)
                {
                    game_api.set_ui_comp_align(this.role, this.id, value);
                }

                _align_type = value;
            }
        }

        private color _color;
        /// <summary>
        /// 文本颜色
        /// </summary>
        public color color
        {
            get => _color;
            set
            {
                if (value != null)
                {
                    game_api.set_ui_comp_font_color(this.role, this.id, value.r, value.g, value.b, value.a);
                }

                _color = value;
            }
        }

        private string _bind_attr;
        /// <summary>
        /// 绑定单位属性到玩家界面控件的属性 文本
        /// </summary>
        public string bind_attr
        {
            get => _bind_attr;
            set
            {
                if (value != null)
                {
                    game_api.set_ui_comp_bind_attr(this.role, this.id, "text_bind", value, 0);
                }

                _bind_attr = value;
            }
        }

        private Unit _bind_attr_unit;
        /// <summary>
        /// 界面控件属性绑定指定单位
        /// </summary>
        public Unit bind_attr_unit
        {
            get => _bind_attr_unit;
            set
            {
                if (value != null)
                {
                    game_api.ui_comp_bind_unit(this.role, this.id, value);
                }

                _bind_attr_unit = value;
            }
        }

    }
}
